import tinymce from 'tinymce/tinymce'
import { fontsizeMap } from '@/constants/fontsizemap'

tinymce.PluginManager.add('fontSize', function (e, t) {
  var n = '字号'
  const r = fontsizeMap,
    i = function (t) {
      e.selection.getNode(),
        (t = r[t]),
        e.formatter.toggle('fontsize', {
          value: t
        }),
        e.undoManager.add()
    }
  var o = function (t, n = '') {
      var i = e.selection.getNode(),
        o = r[n]
      o = Math.floor(100 * parseFloat(o)) / 100
      var a = i ? window.getComputedStyle(i).fontSize : '16pt'
      return (a = Math.floor(((3 * parseFloat(a)) / 4) * 100) / 100), a === o
    },
    a = Object.keys(r).map((item) => {
      return {
        type: 'togglemenuitem',
        text: item,
        onAction: () => {
          i(item)
        },
        onSetup: function (e) {
          e.setActive(o(e, item))
        }
      }
    }),
    s = (e) => {
      let t = !1,
        n = e.selection.getNode(),
        r = e.dom.getParent(n, '.info-block')
      // if (t = !r || e.dom.hasClass(r, "fixed") || void 0 !== r.dataset.enlock || !r.isContentEditable,
      // t) {
      //     let r = e.dom.getParent(n, ".ol-list") || e.dom.getParent(n, ".appendix-list");
      //     r && !e.dom.hasClass(r, "disabled") && (t = !1)
      // }
      return t
    }
  return (
    e.ui.registry.addMenuButton('fontSize', {
      // icon: 'change-case',
      text: '14', // 因为禁用写的固定值
      tooltip: n,
      fetch: (e) => {
        e(a)
      },
      onSetup: (t) => {
        var n = () => {
          t.setDisabled(true) // M1阶段暂时禁用
        }
        return e.on('NodeChange', n), () => e.off('NodeChange', n)
      }
    }),
    {
      getMetadata: function () {
        return {
          name: n,
          url: 'http://sfrj.cn'
        }
      }
    }
  )
})
